<?php
use GatewayClient\Gateway;

class controller_members extends model_members{

    #region 查看IP
    public function members_list_ip()
    {
        $_ip = $this->existsKeyInArray('ip',$_GET,'S');
        $ip = @file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$_ip);
        $ip = json_decode($ip,true);
        if(isset($ip['code']) && $ip['code'] == '0') {
            $html = '<div id="mainbody">';
            $html .= '<div class="main">';
            $html .= '<div class="info">';
            $html .= '<dl><dt>IP地址：</dt><dd>' . $_ip . '</dd></dl>';
            $html .= '<dl><dt>IP信息：</dt><dd>'.$ip['data']['country'];
            $html .=  $ip['data']['area'];
            $html .=  $ip['data']['region'];
            $html .=  $ip['data']['city'];
            $html .=  $ip['data']['isp'];
            $html .= '</dd></dl>';
            $html .= '</div>';
            $html .= '</div>';
            $html .= '</div>';
            $this->dialogue(array(
                'class' => '',
                'body' => $html,
                'no' => array(
                    'text' => '关闭',
                ),
            ));
        }else{
            core::error('查询失败');
        }
    }
    # endregion

	# region 用户等级管理
    //获取分布及查找参数
    private function members_leves_list_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        return $args;
    }
    //拼装页面参数
    private function members_leves_list_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
	public function members_level_list(){
		$basepath = '/members/members_level_list';
		
		$get = true;
        $args = $this->members_leves_list_get_args($get);
        $page_args = $this->members_leves_list_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_members_leves_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("members/members_level_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/members_level_list',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
	}
	//获取添加及编辑页面表单参数
    private function members_level_list_add_edit_args($get = true){
        $para = $get ? $_GET : $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['lid'] = $this->existsKeyInArray('lid',$para,'N');
        $args['title'] = $this->existsKeyInArray('title',$para,'S');
        $args['cointotal'] = $this->existsKeyInArray('cointotal',$para,'N');
        $args['rechargesum'] = $this->existsKeyInArray('rechargesum',$para,'F');
        $args['rechargediscd'] = $this->existsKeyInArray('rechargediscd',$para,'F');
        $args['coinlogdiscd'] = $this->existsKeyInArray('coinlogdiscd',$para,'F');
        $args['pushusergive'] = $this->existsKeyInArray('pushusergive',$para,'F');
        $args['cashtimes'] = $this->existsKeyInArray('cashtimes',$para,'N');
        $args['promotionaward'] = $this->existsKeyInArray('promotionaward',$para,'F');
        if(empty($para['title'])) core::error("等级名称不能为空");
        return $args;
    }
	//添加
    public function members_level_list_add(){
        $basepath = '/members/members_level_list';
        $maxlid = $this->table_maxsort('@@userlevel','lid','1');
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>等级编辑：</dt><dd><input type="text" name="lid" class="int" value="'.$maxlid.'" /></dd></dl>';
        $html .= '<dl><dt>等级说明：</dt><dd><input type="text" name="title" class="int" /></dd></dl>';
        $html .= '<dl><dt>充值金额：</dt><dd><input type="text" name="rechargesum" class="int" value="0" /> 以上</dd></dl>';
        $html .= '<dl><dt>资金流水：</dt><dd><input type="text" name="cointotal" class="int" value="0" /> 以上</dd></dl>';
        $html .= '<dl><dt>充值折扣：</dt><dd><input type="text" name="rechargediscd" class="int" value="0" /></dd></dl>';
        $html .= '<dl><dt>每日提现：</dt><dd><input type="text" name="cashtimes" class="int" value="0" /> 次</dd></dl>';
        $html .= '<dl><dt>流水返点：</dt><dd><input type="text" name="coinlogdiscd" class="int" value="0" /></dd></dl>';
        //$html .= '<dl><dt>推荐奖励：</dt><dd><input type="text" name="pushusergive" class="int" value="0" /> 每人</dd></dl>';
        $html .= '<dl><dt>晋级奖励：</dt><dd><input type="text" name="promotionaward" class="int" value="0" /> '.$this->currencyName.'</dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    //编辑
    public function members_level_list_edit(){
        $basepath = '/members/members_level_list';
        $args['lid'] = $this->existsKeyInArray('lid',$_GET,'N');
        $data = $this->db->getRow('@@userlevel','*',$args);
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>等级编辑：</dt><dd><input type="text" name="lid" class="int" value="'.$data['lid'].'" /></dd></dl>';
        $html .= '<dl><dt>等级说明：</dt><dd><input type="text" name="title" class="int" value="'.$data['title'].'" /></dd></dl>';
        $html .= '<dl><dt>充值金额：</dt><dd><input type="text" name="rechargesum" class="int" value="'.$data['rechargesum'].'" /> 以上</dd></dl>';
        $html .= '<dl><dt>资金流水：</dt><dd><input type="text" name="cointotal" class="int" value="'.$data['cointotal'].'" /> 以上</dd></dl>';
        $html .= '<dl><dt>充值折扣：</dt><dd><input type="text" name="rechargediscd" class="int" value="'.$data['rechargediscd'].'" /></dd></dl>';
        $html .= '<dl><dt>每日提现：</dt><dd><input type="text" name="cashtimes" class="int" value="'.$data['cashtimes'].'" /> 次</dd></dl>';
        $html .= '<dl><dt>流水返点：</dt><dd><input type="text" name="coinlogdiscd" class="int" value="'.$data['coinlogdiscd'].'" /></dd></dl>';
        //$html .= '<dl><dt>推荐奖励：</dt><dd><input type="text" name="pushusergive" class="int" value="'.$data['pushusergive'].'" /> 每人</dd></dl>';
        $html .= '<dl><dt>晋级奖励：</dt><dd><input type="text" name="promotionaward" class="int" value="'.$data['promotionaward'].'" /> '.$this->currencyName.'</dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    //添加数据保存
    public function members_level_list_add_save()
    {
        $args = $this->members_level_list_add_edit_args(false);
        $_result = $this->db->insert('@@userlevel',$args);
        if(!$_result) core::error("添加[".$args['title']."]失败".$_result);
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/members/members_level_list");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    //更新数据保存
    public function members_level_list_edit_save()
    {
        $args = $this->members_level_list_add_edit_args(false);
        $lid = intval($args['lid']);
        unset($args['lid']);
        $_result = $this->db->update('@@userlevel',$args,array('lid'=>$lid));
        if(!$_result) core::error("编辑[".$args['title']."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "编辑[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/members/members_level_list");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    //删除指定行
    public function members_level_list_delete()
    {
        $lid = $this->existsKeyInArray('lid',$_GET,'N');
        if(!$lid) core::__403();
        //删除条件检测
        $deleteid = $this->db->delete('@@userlevel',array('lid'=>$lid));
        if(!$deleteid) core::error('删除操作失败');
        $this->addLog($this->authid,__FUNCTION__,$lid,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/members/members_level_list");',
            ),
        ));
    }
    //删除选定数据行（多行）
    public function members_level_list_delete_list(){
        if(!$this->post) core::__403();
        $ids = $this->existsKeyInArray('ids',$_POST,'S');
        if(empty($ids)) core::error('没有选择要删除的数据行');
        $delid = $this->db->delete_list('@@userlevel','lid',$ids);
        $this->addLog($this->authid,__FUNCTION__,$delid,'');
        if(!$delid) core::error('删除失败');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/members/members_level_list");',
            ),
        ));
    }
    # endregion

    # region 代理等级管理
    //获取分布及查找参数
    private function agent_level_list_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        return $args;
    }
    //拼装页面参数
    private function agent_level_list_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function agent_level_list(){
        $basepath = '/members/agent_level_list';

        $get = true;
        $args = $this->agent_level_list_get_args($get);
        $page_args = $this->agent_level_list_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_agent_level_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);
        $this->display("members/agent_level_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/agent_level_list',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //获取添加及编辑页面表单参数
    private function agent_level_list_add_edit_args($get = true){
        $para = $get ? $_GET : $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['lid'] = $this->existsKeyInArray('lid',$para,'N');
        $args['title'] = $this->existsKeyInArray('title',$para,'S');
        $args['backtotal'] = $this->existsKeyInArray('backtotal',$para,'F');
        $args['rechargediscd'] = $this->existsKeyInArray('rechargediscd',$para,'F');
        $args['backposion'] = $this->existsKeyInArray('backposion',$para,'F');
        $args['pushusergive'] = $this->existsKeyInArray('pushusergive',$para,'F');
        $args['promotionaward'] = $this->existsKeyInArray('promotionaward',$para,'F');
        if(empty($para['title'])) core::error("代理等级名称不能为空");
        return $args;
    }
    //添加
    public function agent_level_list_add(){
        $basepath = '/members/agent_level_list';
        $maxlid = $this->table_maxsort('@@agentlevel','lid','1');
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>等级编辑：</dt><dd><input type="text" name="lid" class="int" value="'.$maxlid.'" /></dd></dl>';
        $html .= '<dl><dt>等级说明：</dt><dd><input type="text" name="title" class="int" value="" /></dd></dl>';
        $html .= '<dl><dt>返水总额：</dt><dd><input type="text" name="backtotal" class="int" /></dd></dl>';
        $html .= '<dl><dt>充值折扣：</dt><dd><input type="text" name="rechargediscd" class="int" value="0" /> %</dd></dl>';
        $html .= '<dl><dt>返点：</dt><dd><input type="text" name="backposion" class="int" value="0" /> %</dd></dl>';
        $html .= '<dl><dt>推荐奖励：</dt><dd><input type="text" name="pushusergive" class="int" value="0" /> '.$this->currencyName.'/每人</dd></dl>';
        $html .= '<dl><dt>晋级奖励：</dt><dd><input type="text" name="promotionaward" class="int" value="0" /> '.$this->currencyName.'</dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    //编辑
    public function agent_level_list_edit(){
        $basepath = '/members/agent_level_list';
        $args['lid'] = $this->existsKeyInArray('lid',$_GET,'N');
        $data = $this->db->getRow('@@agentlevel','*',$args);
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>等级编辑：</dt><dd><input type="text" name="lid" class="int" value="'.$data['lid'].'" /></dd></dl>';
        $html .= '<dl><dt>等级说明：</dt><dd><input type="text" name="title" class="int" value="'.$data['title'].'" /></dd></dl>';
        $html .= '<dl><dt>返水总额：</dt><dd><input type="text" name="backtotal" class="int" value="'.$data['backtotal'].'" /></dd></dl>';
        $html .= '<dl><dt>充值折扣：</dt><dd><input type="text" name="rechargediscd" class="int" value="'.$data['rechargediscd'].'" /> %</dd></dl>';
        $html .= '<dl><dt>流水返点：</dt><dd><input type="text" name="backposion" class="int" value="'.$data['backposion'].'" /> %</dd></dl>';
        $html .= '<dl><dt>推荐奖励：</dt><dd><input type="text" name="pushusergive" class="int" value="'.$data['pushusergive'].'" /> '.$this->currencyName.'/每人</dd></dl>';
        $html .= '<dl><dt>晋级奖励：</dt><dd><input type="text" name="promotionaward" class="int" value="'.$data['promotionaward'].'" /> '.$this->currencyName.'</dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    //添加数据保存
    public function agent_level_list_add_save()
    {
        $args = $this->agent_level_list_add_edit_args(false);
        $_result = $this->db->insert('@@agentlevel',$args);
        if(!$_result) core::error("添加[".$args['title']."]失败".$_result);
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/members/agent_level_list");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    //更新数据保存
    public function agent_level_list_edit_save()
    {
        $args = $this->agent_level_list_add_edit_args(false);
        $lid = intval($args['lid']);
        unset($args['lid']);
        $_result = $this->db->update('@@agentlevel',$args,array('lid'=>$lid));
        if(!$_result) core::error("编辑[".$args['title']."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "编辑[".$args['title']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/members/agent_level_list");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    //删除指定行
    public function agent_level_list_delete()
    {
        $lid = $this->existsKeyInArray('lid',$_GET,'N');
        if(!$lid) core::__403();
        //删除条件检测
        $deleteid = $this->db->delete('@@agentlevel',array('lid'=>$lid));
        if(!$deleteid) core::error('删除操作失败');
        $this->addLog($this->authid,__FUNCTION__,$lid,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/members/agent_level_list");',
            ),
        ));
    }
    //删除选定数据行（多行）
    public function agent_level_list_delete_list(){
        if(!$this->post) core::__403();
        $ids = $this->existsKeyInArray('ids',$_POST,'S');
        if(empty($ids)) core::error('没有选择要删除的数据行');
        $this->addLog($this->authid,__FUNCTION__,$ids,'');
        $delid = $this->db->delete_list('@@agentlevel','lid',$ids);
        if(!$delid) core::error('删除失败');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/members/agent_level_list");',
            ),
        ));
    }
    # endregion

    # region 在线用户
    public function onlineuserlist()
    {
        $para = $_GET;
        $formusers = $this->existsKeyInArray('type',$para,'S','public');
        $this->display("members/onlineuserlist",array(
            'basepath' => "/members/onlineuserlist",
            'thishref' => '/members/onlineuserlist',
            'extra' => '',
            'formusers' => $formusers,
            'searchdata' => array(),
            'container' => '#iframe'
        ));
    }
    # endregion

    # region 用户管理
    //获取分布及查找参数
    private function members_list_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['usertype'] = $this->existsKeyInArray('usertype',$para,'S');
        $args['userlevel'] = $this->existsKeyInArray('userlevel',$para,'S');
        $args['agentlevel'] = $this->existsKeyInArray('agentlevel',$para,'S');
        $args['puid'] = $this->existsKeyInArray('puid',$para,'N');
        $args['t'] = $this->existsKeyInArray('t',$para,'N');
        $args['regip'] = $this->existsKeyInArray('regip',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function members_list_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        $page_args['usertype'] = $args['usertype'];
        $page_args['userLevel'] = $args['userlevel'];
        $page_args['agentLevel'] = $args['agentlevel'];
        if(!empty($args['puid'])) $page_args['puid'] = $args['puid'];
        $page_args['t'] = $args['t'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function members_list(){
        $basepath = '/members/members_list';

        $get = true;
        $args = $this->members_list_get_args($get);
        $page_args = $this->members_list_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_members_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("members/members_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'total' => $datas['total'],
            'userLevel' => $this->mod_members_userLevel_forSelect(),
            'agentLevel' => $this->mod_members_agentLevel_forSelect(),
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/members_list',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //获取添加及编辑页面表单参数
    private function members_list_add_edit_args($get = true){
        $para = $get ? $_GET : $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['uid'] = $this->existsKeyInArray('uid',$para,'N');
        $args['userlevel'] = $this->existsKeyInArray('userlevel',$para,'N');
        $args['agentlevel'] = $this->existsKeyInArray('agentlevel',$para,'N');
        $args['passwd'] = $this->existsKeyInArray('passwd',$para,'S');
        $args['usertype'] = $this->existsKeyInArray('usertype',$para,'N');
        $args['tel'] = $this->existsKeyInArray('tel',$para,'S');
        $args['qq'] = $this->existsKeyInArray('qq',$para,'S');
        $args['wx'] = $this->existsKeyInArray('wx',$para,'S');
        $args['rebate'] = $this->existsKeyInArray('rebate',$para,'F');
        return $args;
    }

    //编辑
    public function members_list_edit(){
        $basepath = '/members/members_list_edit';
        $args['uid'] = $this->existsKeyInArray('uid',$_GET,'N');
        $data = $this->db->getRow('@@users','score,coin,betcoin,uid,uno,username,nickname,usertype,userlevel,agentlevel,tel,qq,wx,parents,regip,regtimes,recharge,profit,lastip,rebate',$args);
        //$agentlevel = $this->db->query("SELECT `lid`,`title` FROM `@@agentlevel` ORDER BY `lid` ASC",3);
        //$userlevel = $this->db->query("SELECT `lid`,`title` FROM `@@userlevel` ORDER BY `lid` ASC",3);

        $redisKey = $this->redisPrefix['MANAGE'] . 'user_' . $args['uid'];
        $result = $this->redisGet($redisKey);
        if(!$result) {
            $result = array();
            $result['parents'] = $this->db->query("SELECT GROUP_CONCAT(nickname SEPARATOR '->') AS nicknames,GROUP_CONCAT(uno SEPARATOR '->') AS unos FROM @@users WHERE uid IN (" . $data['parents'] . "," . $data['uid'] . ") LIMIT 1", 2);

            //$recharge = $this->db->query("SELECT IFNULL(SUM(amount),0) AS _TOTAL FROM `@@users_recharge` WHERE `amount`>0 AND `state`=1 AND `uid`=".$args['uid'],2);
            $result['cash'] = $this->db->query("SELECT IFNULL(SUM(amount),0) AS _TOTAL FROM `@@users_cash` WHERE `state`=1 AND `uid`=" . $args['uid'], 2);

            $sql = "SELECT g.id,g.title,IFNULL(count1,0) AS count FROM `@@games` g LEFT JOIN (SELECT l.gameid,SUM(betcoin) AS count1 FROM `@@betslog` l WHERE `uid`=" . $args['uid'] . " AND `state`=1 GROUP BY l.`gameid`) t1 ON t1.gameid=g.id";
            $result['userSum'] = $this->db->query($sql, 3);

            $sql = "SELECT b.`name`,b.`account`,b.`openadds`,l.`title` FROM `@@users_bank` b,`@@bank_list` l WHERE l.`id`=b.`bankid` AND b.`uid`=" . $args['uid'] . " AND b.`isdelete`=0";
            $result['banks'] = $this->db->query($sql, 3);

            //$sql = "SELECT SUM(profit) AS _TOTAL FROM `@@betslog` WHERE `uid`=" . $args['uid'] . " AND `state`=1 LIMIT 1";
            //$result['profit'] = $this->db->query($sql, 2);
            //$result['profit'] = $result['profit']['_TOTAL'];

            $this->redisSetEx($redisKey, $result, 120);
        }

        $noactivationgive = 0;

        //$statistics = $this->RPC['user']->statisticsAgentForUid($args['uid'],0);

        $this->display($basepath,array(
            'basepath' => $basepath,
            'data' => $data,
            'userlevel' => $this->mod_members_userLevel_forSelect(),
            'agentlevel' => $this->mod_members_agentLevel_forSelect(),
            'parents' => $result['parents'],
            'cash' => $result['cash'],
            'thishref' => $basepath,
            'userSum' => $result['userSum'],
            'banks' => $result['banks'],
            'noactivationgive' => $noactivationgive,
            'redisKey' => $redisKey,
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //更新数据保存
    public function members_list_edit_save()
    {
        $args = $this->members_list_add_edit_args(false);
        $uid = intval($args['uid']);
        unset($args['uid']);
        if(empty($args['passwd'])){
            unset($args['passwd']);
        }else{
            $token = $this->randString(4);
            $makePasswd = $this->encrypt($args['passwd'],'E',$token);
            $args['passwd'] = $makePasswd;
            $args['token'] = $token;
        }

        $_result = $this->db->update('@@users',$args,array('uid'=>$uid));
        if(!$_result) core::error("编辑[".$uid."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "编辑[".$uid."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    //删除指定行
    public function members_list_delete()
    {
        $uid = $this->existsKeyInArray('uid',$_REQUEST,'N');
        //$sql = "UPDATE `@@users` SET `{$field}`=ABS(`{$field}`-1) WHERE `id`={$id}";
        $sql = "UPDATE `@@users` SET `isdelete`=1 WHERE `uid`={$uid} LIMIT 1";
        $this->addLog($this->authid,__FUNCTION__,$uid);
        $data = $this->db->query($sql,0);
        if(!$data) core::error('用户删除失败，请重试！');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "用户删除成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    //恢复指定的行
    public function members_list_recovery(){
        $uid = $this->existsKeyInArray('uid',$_REQUEST,'N');
        //$sql = "UPDATE `@@users` SET `{$field}`=ABS(`{$field}`-1) WHERE `id`={$id}";
        $sql = "UPDATE `@@users` SET `isdelete`=0 WHERE `uid`={$uid} LIMIT 1";
        $this->addLog($this->authid,__FUNCTION__,$uid);
        $data = $this->db->query($sql,0);
        if(!$data) core::error('用户恢复失败，请重试！');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "用户恢复成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    //删除选定数据行（多行）
    public function members_list_delete_list(){
        if(!$this->post) core::__403();
        $ids = $this->existsKeyInArray('ids',$_POST,'S');
        if(empty($ids)) core::error('没有选择要删除的数据行');
        $this->addLog($this->authid,__FUNCTION__,$ids);
        $deid = $this->db->delete_list('@@users','uid',$ids);
        if(!$deid) core::error('删除失败');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/members/members_list");',
            ),
        ));
    }
    # endregion

    # region 代理用户管理
    //获取分布及查找参数
    private function agentuser_list_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-01-01',time());
        $endTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['sortfield'] = $this->existsKeyInArray('sortfield',$para,'S');
        $args['sorttype'] = $this->existsKeyInArray('sorttype',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$endTime);
        return $args;
    }
    //拼装页面参数
    private function agentuser_list_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if($args['sortfield'] != '') $page_args['sortfield'] = $args['sortfield'];
        if($args['sorttype'] != '') $page_args['sorttype'] = $args['sorttype'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function agentuser_list(){
        $basepath = '/members/agentuser_list';

        $get = true;
        $args = $this->agentuser_list_get_args($get);
        $page_args = $this->agentuser_list_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_agentuser_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("members/agentuser_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'userLevel' => $this->mod_members_userLevel_forSelect(),
            'agentLevel' => $this->mod_members_agentLevel_forSelect(),
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/agentuser_list',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //获取添加及编辑页面表单参数
    private function agentuser_list_add_edit_args($get = true){
        $para = $get ? $_GET : $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['uid'] = $this->existsKeyInArray('uid',$para,'N');
        $args['userlevel'] = $this->existsKeyInArray('userlevel',$para,'N');
        $args['agentlevel'] = $this->existsKeyInArray('agentlevel',$para,'N');
        $args['passwd'] = $this->existsKeyInArray('passwd',$para,'S');
        $args['usertype'] = $this->existsKeyInArray('usertype',$para,'N');
        $args['tel'] = $this->existsKeyInArray('tel',$para,'S');
        $args['qq'] = $this->existsKeyInArray('qq',$para,'S');
        $args['wx'] = $this->existsKeyInArray('wx',$para,'S');
        return $args;
    }

    //编辑
    public function agentuser_list_edit(){
        $basepath = '/members/agentuser_list_edit';
        $args['uid'] = $this->existsKeyInArray('uid',$_GET,'N');
        $data = $this->db->getRow('@@users','score,coin,betcoin,uid,uno,username,nickname,usertype,userlevel,agentlevel,tel,qq,wx,parents,regip,regtimes,recharge,profit,lastip',$args);
        //$agentlevel = $this->db->query("SELECT `lid`,`title` FROM `@@agentlevel` ORDER BY `lid` ASC",3);
        //$userlevel = $this->db->query("SELECT `lid`,`title` FROM `@@userlevel` ORDER BY `lid` ASC",3);

        $redisKey = $this->redisPrefix['MANAGE'] . 'user_' . $args['uid'];
        $result = $this->redisGet($redisKey);
        if(!$result) {
            $result['parents'] = $this->db->query("SELECT GROUP_CONCAT(nickname SEPARATOR '->') AS nicknames,GROUP_CONCAT(uno SEPARATOR '->') AS unos FROM @@users WHERE uid IN (" . $data['parents'] . "," . $data['uid'] . ") LIMIT 1", 2);

            //$recharge = $this->db->query("SELECT IFNULL(SUM(amount),0) AS _TOTAL FROM `@@users_recharge` WHERE `amount`>0 AND `state`=1 AND `uid`=".$args['uid'],2);
            $result['cash'] = $this->db->query("SELECT IFNULL(SUM(amount),0) AS _TOTAL FROM `@@users_cash` WHERE `state`=1 AND `uid`=" . $args['uid'], 2);

            $sql = "SELECT g.id,g.title,IFNULL(count1,0) AS count FROM `@@games` g LEFT JOIN (SELECT l.gameid,SUM(betcoin) AS count1 FROM `@@betslog` l WHERE `uid`=" . $args['uid'] . " AND `state`=1 GROUP BY l.`gameid`) t1 ON t1.gameid=g.id";
            $result['userSum'] = $this->db->query($sql, 3);

            $sql = "SELECT b.`name`,b.`account`,b.`openadds`,l.`title` FROM `@@users_bank` b,`@@bank_list` l WHERE l.`id`=b.`bankid` AND b.`uid`=" . $args['uid'];
            $result['banks'] = $this->db->query($sql, 3);

            //$sql = "SELECT SUM(profit) AS _TOTAL FROM `@@betslog` WHERE `uid`=" . $args['uid'] . " AND `state`=1 LIMIT 1";
            //$result['profit'] = $this->db->query($sql, 2);
            //$result['profit'] = $result['profit']['_TOTAL'];

            $this->redisSetEx($redisKey, $result, 120);
        }

        $noactivationgive = 0;

        //$statistics = $this->RPC['user']->statisticsAgentForUid($args['uid'],0);

        $this->display($basepath,array(
            'basepath' => $basepath,
            'data' => $data,
            'userlevel' => $this->mod_members_userLevel_forSelect(),
            'agentlevel' => $this->mod_members_agentLevel_forSelect(),
            'parents' => $result['parents'],
            'cash' => $result['cash'],
            'thishref' => $basepath,
            'userSum' => $result['userSum'],
            'banks' => $result['banks'],
            'noactivationgive' => $noactivationgive,
            'redisKey' => $redisKey,
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //更新数据保存
    public function agentuser_list_edit_save()
    {
        $args = $this->agentuser_list_add_edit_args(false);
        $uid = intval($args['uid']);
        unset($args['uid']);
        if(empty($args['passwd'])){
            unset($args['passwd']);
        }else{
            $token = $this->randString(4);
            $makePasswd = $this->encrypt($args['passwd'],'E',$token);
            $args['passwd'] = $makePasswd;
            $args['token'] = $token;
        }

        $_result = $this->db->update('@@users',$args,array('uid'=>$uid));
        if(!$_result) core::error("编辑[".$uid."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "编辑[".$uid."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    //删除指定行
    public function agentuser_list_delete()
    {
        $uid = $this->existsKeyInArray('id',$_REQUEST,'N');
        //$sql = "UPDATE `@@users` SET `{$field}`=ABS(`{$field}`-1) WHERE `id`={$id}";
        $sql = "UPDATE `@@users` SET `isdelete`=1 WHERE `uid`={$uid}";

        $data = $this->db->query($sql,0);
        $this->addLog($this->authid,__FUNCTION__,$uid);
        if(!$data) core::error('用户删除失败，请重试！');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "用户删除成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    //恢复指定的行
    public function agentuser_list_recovery(){
        $uid = $this->existsKeyInArray('uid',$_REQUEST,'N');
        //$sql = "UPDATE `@@users` SET `{$field}`=ABS(`{$field}`-1) WHERE `id`={$id}";
        $sql = "UPDATE `@@users` SET `isdelete`=0 WHERE `uid`={$uid}";
        $data = $this->db->query($sql,0);
        $this->addLog($this->authid,__FUNCTION__,$uid);
        if(!$data) core::error('用户恢复失败，请重试！');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "用户恢复成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    //删除选定数据行（多行）
    public function agentuser_list_delete_list(){
        if(!$this->post) core::__403();
        $ids = $this->existsKeyInArray('ids',$_POST,'S');
        if(empty($ids)) core::error('没有选择要删除的数据行');
        $deid = $this->db->delete_list('@@users','uid',$ids);
        $this->addLog($this->authid,__FUNCTION__,$ids);
        if(!$deid) core::error('删除失败');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '返回',
                'func' => 'JumpMainFrame("/members/agentuser_list");',
            ),
        ));
    }
    # endregion

    # region 资金帐变
    //获取参数
    private function coinlog_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['liqtype'] = $this->existsKeyInArray('liqtype',$para,'N');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function coinlog_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if(!empty($args['liqtype'])) $page_args['liqtype'] = $args['liqtype'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function coinlog()
    {
        $basepath = '/members/coinlog';

        $get = true;
        $args = $this->coinlog_get_args($get);
        $page_args = $this->coinlog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_coinlog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/coinlog_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'userLevel' => $this->mod_members_userLevel_forSelect(),
            'agentLevel' => $this->mod_members_agentLevel_forSelect(),
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/coinlog',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    # endregion

    # region 积分帐变
    //获取参数
    private function scorelog_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['liqtype'] = $this->existsKeyInArray('liqtype',$para,'N');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function scorelog_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if(!empty($args['liqtype'])) $page_args['liqtype'] = $args['liqtype'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function scorelog()
    {
        $basepath = '/members/scorelog';

        $get = true;
        $args = $this->scorelog_get_args($get);
        $page_args = $this->scorelog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_scorelog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("members/scorelog_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'userLevel' => $this->mod_members_userLevel_forSelect(),
            'agentLevel' => $this->mod_members_agentLevel_forSelect(),
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/scorelog',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    # endregion

    # region 赠送资金帐变
    //获取参数
    private function givecoinlog_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['liqtype'] = $this->existsKeyInArray('liqtype',$para,'N');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function givecoinlog_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if(!empty($args['liqtype'])) $page_args['liqtype'] = $args['liqtype'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function givecoinlog()
    {
        $basepath = '/members/givecoinlog';

        $get = true;
        $args = $this->givecoinlog_get_args($get);
        $page_args = $this->givecoinlog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_givecoinlog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/givecoinlog_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'userLevel' => $this->mod_members_userLevel_forSelect(),
            'agentLevel' => $this->mod_members_agentLevel_forSelect(),
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/givecoinlog',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    //更新状态
    public function givecoinlog_state(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        $field = $this->existsKeyInArray('field',$_GET,'S');
        $page_args = array(
            'page' => $this->existsKeyInArray('page',$_GET,'N',1),
        );
        if(!$id || empty($field)) core::__403();
        $updateid = $this->update_state('@@givecoinlog',$id,$field);
        if(!$updateid) core::error('状态更新失败');
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "状态更新成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
        $this->pushUpdatecache();
    }
    # endregion

    # region 转包记录
    //获取参数
    private function transferlog_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['liqtype'] = $this->existsKeyInArray('liqtype',$para,'N');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function transferlog_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if(!empty($args['liqtype'])) $page_args['liqtype'] = $args['liqtype'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function transferlog()
    {
        $basepath = '/members/transferlog';

        $get = true;
        $args = $this->transferlog_get_args($get);
        $page_args = $this->transferlog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_transferlog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/transferlog_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/transferlog',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    # endregion

    # region 发包记录
    //获取参数
    private function betslog_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['state'] = $this->existsKeyInArray('state',$para,'S');
        $args['gameid'] = $this->existsKeyInArray('gameid',$para,'S');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        $args['usertype'] = $this->existsKeyInArray('usertype',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function betslog_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if($args['state']!='') $page_args['state'] = $args['state'];
        if($args['gameid']!='') $page_args['gameid'] = $args['gameid'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        if($args['usertype']!='') $page_args['usertype'] = $args['usertype'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function betslog()
    {
        $basepath = '/members/betslog';

        $get = true;
        $args = $this->betslog_get_args($get);
        $page_args = $this->betslog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_betslog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/betslog_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'total' => $datas['total'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/betslog',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe',
            'games' => $this->mod_games_items(),
        ));
    }
    # endregion

    # region 红包参与记录
    //获取参数
    private function betslogforuser_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['state'] = $this->existsKeyInArray('state',$para,'S');
        $args['gameid'] = $this->existsKeyInArray('gameid',$para,'S');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        $args['isusertype'] = $this->existsKeyInArray('isusertype',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function betslogforuser_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['gameid'])) $page_args['gameid'] = $args['gameid'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if($args['state']!='') $page_args['state'] = $args['state'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        if($args['isusertype']!='') $page_args['isusertype'] = $args['isusertype'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    public function betslogforuser(){
        $basepath = '/members/betslogforuser';

        $get = true;
        $args = $this->betslogforuser_get_args($get);
        $page_args = $this->betslogforuser_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_betslogforuser_list($args);




        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/betslogforuser_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
//            'total' => $datas['total'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/betslogforuser',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe',
            'games' => $this->mod_games_items(),
        ));
    }
    # endregion

    # region 抢包明细
    public function betslog_grablist()
    {
        $issue = $this->existsKeyInArray('issue', $_GET,'S');
        $gamename = $this->existsKeyInArray('gamename', $_GET,'S');
        $datas = $this->mod_grablog_list($issue);
        $issue = $datas['datas']['datas'];
        $coin = 0;
        $ticket = 0;
        $winerprofit = 0;
        $html = '<table width="100%" class="tablist">
                        <tr>
                            <td colspan="2">'.$gamename.'期号：'.$issue['issue'];
                            if(empty($issue['usertype'])) $html .= '<i class="trygame">试</i>';
                            if(!empty($issue['pass'])) $html .= '<i class="mastpass">令</i>';
                            $html .= '
                            </td><td>红包金额：'.$issue['coin'].'</td>';
                            if($issue['gameid']==3) $html .= '<td>'.$issue['mantissa'].'尾</td>';
                            $html .= '<td>'.$issue['need'].'包</td><td colspan="4">'.$issue['usedtimes'].'秒抢光</td>
                        </tr>
                        <tr class="trbg">
                            <th>玩家号码</th>
                            <th>玩家昵称</th>
                            <th>红包金额</th>
                            <th>牌型</th>
                            <th>门票</th>
                            <th>抽水</th>
                            <th>本期盈亏</th>
                            <th width="160">参与时间</th>
                        </tr>';
//                            echo '<pre>';
//                            var_dump($datas['datas']['grabusers']);
        foreach ($datas['datas']['grabusers'] as $v)
        {
            $tip = '';
            if($this->deep_in_array($v['userid'], 'uid', $this->autosenduserlist)){
                $tip = '<i class="trygame">机</i>';
            }
            $html .= '<tr>
                            <td>'.(isset($v['uno'])?$v['uno']:'-').$tip.'</td>
                            <td>'.(isset($v['nickname'])?$v['nickname']:'-').'</td>
                            <td>'.$v['coin'].'</td>
                            <td>'.$v['cardtitle'].'</td>
                            <td>'.($v['ticket']>0?$v['ticket']:'-').'</td>
                            <td>'.($v['winerprofit']>0?$v['winerprofit']:'-').'</td>
                            <td>'.$v['profit'].'</td>
                            <td>'.date('Y-m-d H:i:s',$v['times']).'</td>
                        </tr>';
            $coin += floatval($v['coin']);
            $ticket += floatval($v['ticket']);
            $winerprofit += floatval($v['winerprofit']);
        }
        $html .= '<tr><td colspan="2"></td><td>'.$this->formatCoin($coin).'</td><td></td><td>'.$this->formatCoin($ticket).'</td><td>'.$this->formatCoin($winerprofit).'</td><td colspan="2"></td></tr>';
        $html .= '</table>';
        $this->dialogue(array(
            'class' => 'big',
            'body' => $html,
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    # endregion

    # region 用户银行卡管理
    public function userbanks_delete(){
        $id = $this->existsKeyInArray('id',$_GET,'N');
        if(!$id) core::__403();
        //删除条件检测
        //$deleteid = $this->db->delete('@@users_bank',array('id'=>$id));
        //if(!$deleteid) core::error('删除操作失败');
        $updateLog = array(
            "isdelete" => 1,
        );
        $this->table_row_save('@@users_bank', $updateLog, array('id'=>$id),true);
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => 'JumpMainFrame("/members/userbanks");',
            ),
        ));
    }
    //获取参数
    private function userbanks_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['bankid'] = $this->existsKeyInArray('bankid',$para,'N');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function userbanks_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['bankid'])) $page_args['bankid'] = $args['bankid'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function userbanks()
    {
        $basepath = '/members/userbanks';

        $get = true;
        $args = $this->userbanks_get_args($get);
        $page_args = $this->userbanks_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_userbanks_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("members/userbanks",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'banks' => $this->mod_banklist_for_selectoption(),
            'thishref' => '/members/userbanks',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe',
            'games' => $this->mod_games_items(),
        ));
    }

    public function userbanks_edit()
    {
        $id = $this->existsKeyInArray('id',$_GET,'N');
        $sql = "SELECT `uid`,`bankid`,`name`,`account`,`openadds` FROM `@@users_bank` WHERE `id`=".$id.' LIMIT 1';
        $data = $this->db->query($sql, 2);
        $banklists = $this->db->query("SELECT `id`,`code`,`title` FROM `@@bank_list` WHERE `state`=1 ORDER BY `sort` ASC",3);;

        $basepath = '/members/userbanks';

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="_edit_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家UID：</dt><dd><input type="text" name="uid" class="int" value="'.$data['uid'].'" readonly /></dd></dl>';
        $html .= '<dl><dt>开户行：</dt><dd><select name="bankid">';
        foreach ($banklists AS $key=>$val) {
            if( $val['id'] == $data['bankid'] ){
                $html .= '<option value="' .$val['id'].'" selected>'.$val['title'].'</option>';
            }else{
                $html .= '<option value="' .$val['id'].'">'.$val['title'].'</option>';
            }
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>账号姓名：</dt><dd><input type="text" name="name" class="int" value="'.$data['name'].'"  /></dd></dl>';
        $html .= '<dl><dt>账号：</dt><dd><input type="text" name="account" class="int" value="'.$data['account'].'"  /></dd></dl>';
        $html .= '<dl><dt>账号地址：</dt><dd><input type="text" name="openadds" class="int" value="'.$data['openadds'].'" /></dd></dl>';
        $html .= '<input type="hidden" name="id" class="int" value="'.$id.'" />';

        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=_edit_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }

    public function userbanks_edit_save()
    {
        $args = $this->userbanks_add_edit_args(false);
        $id = $args['id'];
        $uid = $args['uid'];
        unset($args['uid']);
        unset($args['id']);
        $_result = $this->db->update('@@users_bank',$args,array('id'=>$id));
        if(!$_result) core::error("编辑[".$args['uid']."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "编辑[".$uid."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/members/userbanks");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }

    public function userbanks_add_save()
    {
        $para =  $_POST;
        unset($para["client_type"]);
        $args = array();
        $uno = $this->existsKeyInArray('uno',$para,'N');
        $args['bankid'] = $this->existsKeyInArray('bankid',$para,'N');
        $args['name'] = $this->existsKeyInArray('name',$para,'S');
        $args['account'] = $this->existsKeyInArray('account',$para,'S');
        $args['openadds'] = $this->existsKeyInArray('openadds',$para,'S');

        $sql = "SELECT `uid` FROM `@@users` WHERE `uno`='{$uno}' LIMIT 1";
        $user = $this->db->query($sql,2);
        $para['uid'] = $user['uid'];
        if(empty($uno)) core::error("玩家号码不能为空");
        if(empty($para['uid'])) core::error("玩家不存在");
        if(empty($para['bankid'])) core::error("开户行不能为空");
        if(empty($para['name'])) core::error("账号姓名不能为空");
        if(empty($para['account'])) core::error("账号不能为空");
        unset($para['uno']);
        $_result = $this->db->insert('@@users_bank',$para);
        if(!$_result) core::error("新增[".$uno."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "新增[".$uno."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => 'JumpMainFrame("/members/userbanks");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));

    }

    private function userbanks_add_edit_args($get = true)
    {
        $para = $get ? $_GET : $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['id'] = $this->existsKeyInArray('id',$para,'N');
        $args['uid'] = $this->existsKeyInArray('uid',$para,'N');
        $args['bankid'] = $this->existsKeyInArray('bankid',$para,'N');
        $args['name'] = $this->existsKeyInArray('name',$para,'S');
        $args['account'] = $this->existsKeyInArray('account',$para,'S');
        $args['openadds'] = $this->existsKeyInArray('openadds',$para,'S');
        if(empty($para['uid'])) core::error("玩家UID不能为空");
        if(empty($para['bankid'])) core::error("开户行不能为空");
        if(empty($para['name'])) core::error("账号姓名不能为空");
        if(empty($para['account'])) core::error("账号不能为空");
        return $args;
    }

    //添加
    public function userbanks_add(){
        $basepath = '/members/userbanks';
        $banklists = $this->db->query("SELECT `id`,`code`,`title` FROM `@@bank_list` WHERE `state`=1 ORDER BY `sort` ASC",3);;
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="_add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家号码：</dt><dd><input type="text" name="uno" class="int" value=""  /></dd></dl>';
        $html .= '<dl><dt>开户行：</dt><dd><select name="bankid">';
        foreach ($banklists AS $key=>$val) {
            $html .= '<option value="' .$val['id'].'">'.$val['title'].'</option>';
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>账号姓名：</dt><dd><input type="text" name="name" class="int" value=""  /></dd></dl>';
        $html .= '<dl><dt>账号：</dt><dd><input type="text" name="account" class="int" value=""  /></dd></dl>';
        $html .= '<dl><dt>账号地址：</dt><dd><input type="text" name="openadds" class="int" value="" /></dd></dl>';

        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=_add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }

    # endregion
    # region 积分充值处理
    // 手动给玩家充值积分
    public function rechargescoretouser()
    {
        $paras = $_GET;
        $uno = $this->existsKeyInArray('uno', $paras, 'S');
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="/members/rechargescoretouser_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家号码：</dt><dd><input type="text" name="uno" placeholder="请输入玩家号码" value="'.$uno.'" /></dd></dl>';
        $html .= '<dl><dt>帐变类型：</dt><dd><select name="liqtype" style="width:80px">';
        foreach ($this->scoreliqtype as $k=>$v){
            $html .= '<option value="'.$k.'">'.$v.'</option>';
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>积分数量：</dt><dd><input type="text" name="score" placeholder="请输入充值的积分数量" /> </dd></dl>';
        $html .= '<dl><dt>备注内容：</dt><dd><input type="text" name="info" placeholder="手动充值说明" /> </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    public function rechargescoretouser_save(){
        $paras = $_POST;
        $uno = $this->existsKeyInArray('uno', $paras, 'S');
        $score = $this->existsKeyInArray('score', $paras, 'F');
        $info = $this->existsKeyInArray('info', $paras, 'S');
        $liqtype = $this->existsKeyInArray('liqtype', $paras, 'N');
        if(empty($uno) || empty($score) || empty($info) || empty($liqtype)){
            core::error('积分充值内容不完整，充值失败！');
        }
        #查找玩家
        $sql = "SELECT `uid`,`score`,`parentid` FROM `@@users` WHERE `uno`='{$uno}' LIMIT 1";
        $user = $this->db->query($sql,2);
        if(!$user) core::error('玩家不存在');
        $paras['nowtime'] = time();
        $this->addLog($this->authid,__FUNCTION__,$user['uid'],'');
        # 入帐到玩家帐号
        //开始事务处理
        $this->db->transaction('begin');
        try{
            $scoreLog = array(
                'uid' => $user['uid'],
                'score' => $score,
                'liqtype' => 3,
                'ex2'=>$info,
            );
            $this->set_score($scoreLog);

            $this->db->transaction('commit');
        }catch(Exception $e){
            $this->db->transaction('rollBack');
            core::error($e->getMessage());
        }

        $this->dialogue(array(
            'type' => 'success',
            'text' => "手动给玩家[{$uno}]充值积分{$score}成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    # endregion

    # region 充值处理
    // 导出充值数据
    public function rechargetoexcel(){

        $get = true;
        $args = $this->rechargelog_get_args($get);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_rechargelog_list($args);

        $args['ps'] = $datas['record'];
        $datas = $this->mod_rechargelog_list($args);

        $titles = '';
        foreach ($datas['datas'] as $k => $v) {
            $rs[$kkk] = $res->field('l.id lid,l.user_id,l.shop_id,l.code_num,l.code_src,l.winning_time,l.exchange_time,l.status,l.item_id iid,i.title,i.money,s.coder,u.nickname,u.head,s.manager,s.phone')->alias('l')->where($where)->join('sd_item i ON i.id=l.item_id')->join('left join  sd_shop s ON s.id=l.shop_id')->join('sd_user u ON u.id=l.user_id')->page($vvv.', 10000')->select();

            $str[$kkk] = "用户昵称,兑奖门店号,核销员,核销员手机号,中奖时间,兑换时间,奖项名称,中奖金额,中奖码,兑换状态";

            $exl11[$kkk] = explode(',',$str[$kkk]);
            foreach ($rs[$kkk] as $k => $v){

                if (!$v['nickname']) $v['nickname']           = '暂无数据';
                if (!$v['coder']) $v['coder']                 = '暂无数据';
                if (!$v['manager']) $v['manager']             = '暂无数据';
                if (!$v['phone']) $v['phone']                 = '暂无数据';
                if (!$v['winning_time']) $v['winning_time']   = '暂无数据';
                if (!$v['exchange_time']) $v['exchange_time'] = '暂无数据';
                if (!$v['title']) $v['title']                 = '暂无数据';
                if (!$v['money']) $v['money']                 = '暂无数据';

                $exl[$kkk][] = array(
                    $v['nickname'],$v['coder'],$v['manager'],$v['phone'],$v['winning_time'],$v['exchange_time'],$v['title'],$v['money'],$ssssd[$v['status']]
                );

            }

            $this->exportToExcel('充值记录_'. date('Y-m-d',time()).$vvv.'.csv',$exl11[$kkk],$exl[$kkk]);
        }
    }
    // 手动给玩家充值
    public function rechargetouser()
    {
		$paras = $_GET;
		$uno = $this->existsKeyInArray('uno', $paras, 'S');
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="/members/rechargetouser_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家号码：</dt><dd><input type="text" name="uno" placeholder="请输入玩家号码" value="'.$uno.'" /></dd></dl>';
        $html .= '<dl><dt>充值金额：</dt><dd><input type="text" name="amount" placeholder="请输入充值的金额" /> </dd></dl>';
        $html .= '<dl><dt>充值赠送：</dt><dd><input type="text" name="give" placeholder="充值赠送百分比（%）" /></dd></dl>';
        $html .= '<dl><dt>充值类型：</dt><dd><select name="rechargetype"><option value="21">人工充值</option><option value="31">活动优惠</option><option value="23">注册赠送</option></select></dd></dl>';
        $html .= '<dl><dt>备注内容：</dt><dd><input type="text" name="info" placeholder="手动充值说明" /> </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    //提出玩家金币
    public function downcointouser()
    {
        $paras = $_GET;
        $uno = $this->existsKeyInArray('uno', $paras, 'S');
        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="downcoin_save" action="/members/downcointouser_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家号码：</dt><dd><input type="text" name="uno" placeholder="请输入玩家号码" value="'.$uno.'" /></dd></dl>';
        $html .= '<dl><dt>提出金额：</dt><dd><input type="text" name="amount" placeholder="请输入充值的金额" /> </dd></dl>';
        $html .= '<dl><dt>备注内容：</dt><dd><input type="text" name="info" placeholder="手动充值说明" /> </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=downcoin_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }

    public function downcointouser_save()
    {
        $paras = $_POST;
        $uno = $this->existsKeyInArray('uno', $paras, 'S');
        $amount = $this->existsKeyInArray('amount', $paras, 'F');
        $info = $this->existsKeyInArray('info', $paras, 'S');

        if(empty($uno) || empty($amount) || empty($info)){
            core::error('内容填写不完整，提出失败！');
        }

        $sql = "SELECT `uid`,`uno`,`nickname`,`coin`,`parentid`,`recharge`,`usertype` FROM `@@users` WHERE `uno`='{$uno}' LIMIT 1";
        $user = $this->db->query($sql,2);
        if(!$user) core::error('玩家不存在');
        $paras['nowtime'] = time();
        $this->addLog($this->authid,__FUNCTION__,$user['uid'],'');
        //开始事务处理
        $this->db->transaction('begin');
        try{
            $coinLog = array(
                'uid' => $user['uid'],
                'coin' => -$amount,
                'liqtype' => 33,
                'ex1' => 0,
                'ex2' => date('YmdHis'),
                'ex3' => $info,
            );
            $this->set_coin($coinLog);
            $this->db->transaction('commit');
        }catch(Exception $e){
            $this->db->transaction('rollBack');
            core::error($e->getMessage());
        }
        $sql = "SELECT `uid`,`coin` FROM `@@users` WHERE `uno`='{$uno}' LIMIT 1";
        $user = $this->db->query($sql,2);

        $this->pushClient($uno,array(
            'cmd' => 'updateusercoin',
            'state' => 200,
            'usercoin' => $user['coin'],
        ));
        $this->dialogue(array(
            'type' => 'success',
            'text' => "手动给玩家[{$uno}]提出{$amount}成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));

    }

    public function rechargetouser_save(){
        $paras = $_POST;
        $uno = $this->existsKeyInArray('uno', $paras, 'S');
        $amount = $this->existsKeyInArray('amount', $paras, 'F');
        $give = $this->existsKeyInArray('give', $paras, 'F',0);
        $info = $this->existsKeyInArray('info', $paras, 'S');
        $rechargetype = $this->existsKeyInArray('rechargetype', $paras, 'N', 21);
        if(empty($uno) || empty($amount) || empty($info)){
            core::error('充值内容不完整，充值失败！');
        }
        #查找玩家
        $sql = "SELECT `uid`,`uno`,`nickname`,`coin`,`parentid`,`recharge`,`usertype` FROM `@@users` WHERE `uno`='{$uno}' LIMIT 1";
        $user = $this->db->query($sql,2);
        if(!$user) core::error('玩家不存在');
        $paras['nowtime'] = time();
        $this->addLog($this->authid,__FUNCTION__,$user['uid'],'');
        # 入帐到玩家帐号
        //开始事务处理
        $this->db->transaction('begin');
        try{
            # 记录充值日志
            # 生成订单号
            $rechargeid = $this->neworderno();

            $id = 0;
            //$rechargeid = 0;
            $liqtype = 23;

            // if($rechargetype!=23) {
                $liqtype = $rechargetype;
                switch ($rechargetype){
                    case 31: // 活动优惠
                        $payway = array(
                            'paywayid' => 3,
                            'lineid' => 2,
                            'bankid' => 24,
                        );
                        break;
                    case 23: // 注册赠送
                        $payway = array(
                            'paywayid' => 3,
                            'lineid' => 2,
                            'bankid' => 24,
                        );
                        break;
                    case 21: // 人工充值
                        $payway = array(
                            'paywayid' => 1,
                            'lineid' => 1,
                            'bankid' => 24,
                        );
                        break;
                    default:
                        $payway = array(
                            'paywayid' => 1,
                            'lineid' => 1,
                            'bankid' => 24,
                        );
                        break;
                }
                # 保存到充值日志中
                $recharge_log = array(
                    'uid' => $user['uid'],
                    'rechargeid' => $rechargeid,
                    'amount' => $amount,
                    'rechargeamount' => $amount,
                    'coin' => $user['coin'],
                    'bankid' => $payway['bankid'],
                    'paywayid' => $payway['paywayid'],
                    'lineid' => $payway['lineid'],
                    'state' => 1,
                    'actiontime' => $paras['nowtime'],
                    'info' => $info,
                    'usertype' => $user['usertype'],
                );
                $id = $this->table_row_save('@@users_recharge', $recharge_log, array(),false);

                /*
                # 充值成功后把上级的代理推荐赠送的金额激活
                $sql = "UPDATE `@@givecoinlog` SET `state`=1 WHERE `uid`=".$user['parentid']." AND `liqtype`=25 AND `ex1`=".$user['uid']." AND `state`=0 LIMIT 1";
                $this->db->query($sql,1);
                # 充值成功后把注册赠送的记录激活
                $sql = "UPDATE `@@givecoinlog` SET `state`=1 WHERE `uid`=".$user['uid']." AND `liqtype`=23 AND `state`=0 LIMIT 1";
                $this->db->query($sql,1);
                */
                //$sql = "SELECT COUNT(id) AS _TOTAL,IFNULL(SUM(rechargeAmount),0) AS _SUM FROM @@users_recharge WHERE state=1 AND `uid`=".$user['uid'];
                //echo $sql;
                //$rc = $this->db->query($sql,2);
                //$rechargeCount = $rc['_TOTAL'];
                # 充值总额要加上本次的充值金额，用户的充值总额是要在setCoin执行后才会更新
                $rechargeSum = floatval($user['recharge']) + floatval($amount);

                $sumrechargecoin = $this->config['sumrechargecoin'];
                # $sumrechargegive = $utility->getSystemParas('sumrechargegive');

                # 当用户充值的金额达到指定的赠送额度后，给当前用户和推荐人加入赠送的金额
                if($rechargeSum >= floatval($sumrechargecoin)) {

                    $sql = "SELECT `uid`,`uno`,`coin`,`score`,`parentid`,`parents`,`tel`,`agentlevel`,`userlevel` FROM `@@users` WHERE `uid`='" . $user['parentid'] . "' AND `usertype`>0 LIMIT 1";
                    $parent = $this->db->query($sql, 2);

                    if($parent) {
                        # 查找是否已经赠送,如果有赠送即不再赠送，没有就赠送过去
                        $sql = "SELECT COUNT(1) AS _TOTAL FROM `@@recharge_give` WHERE `uid`={$parent['uid']} AND `fromuid`={$user['uid']} LIMIT 1";
                        $isgive = $this->db->query($sql, 2);
                        if($isgive['_TOTAL'] == 0) {
                            $sql = 'SELECT `pushusergive` FROM `@@agentlevel` WHERE `lid`=' . intval($parent['agentlevel']) . ' LIMIT 1';
                            $agent = $this->db->query($sql, 2);
                            if ($agent['pushusergive'] > 0) {
                                $this->set_coin(array(
                                        'uid' => $parent['uid'],
                                        'coin' => $agent['pushusergive'],
                                        'liqtype' => 25,
                                        'ex1' => $user['uid'],
                                        'ex2' => '',
                                        'ex3' => $user['nickname'].'('.$user['uno'].')存款满' . $sumrechargecoin . '赠送',
                                    )
                                );
                                # 有赠送的把它记录到赠送库里
                                $recharge_give = array(
                                    "uid" => $parent['uid'],
                                    "fromuid" => $user['uid'],
                                    "coin" => $agent['pushusergive'],
                                    "actiontimes" => time(),
                                    "liqtype" => 1,
                                );
                                $id = $this->table_row_save('@@recharge_give', $recharge_give, false);
                            }
                        }
                    }
                }
            // }

            $coinLog = array(
                'uid' => $user['uid'],
                'coin' => $amount,
                'liqtype' => $liqtype,
                'ex1' => $id,
                'ex2' => $rechargeid,
                'ex3' => $info,
            );
            $this->set_coin($coinLog);
            # 充值赠送
            if(floatval($give)>0) {
                $giveCoin = $amount * $give / 100;
                $this->set_coin(array(
                    'uid' => $user['uid'],
                    'coin' => $giveCoin,
                    'liqtype' => 27,
                    'ex1' => $id,
                    'ex2' => $rechargeid,
                    'ex3' => $amount .'×'.$give.'%',
                ));
            }

            # 处理VIP升级
            //$this->updateUserVip($user['uid']);

            $this->db->transaction('commit');
        }catch(Exception $e){
            $this->db->transaction('rollBack');
            core::error($e->getMessage());
        }
        # 通知Gateway用户要更新余额
        # 通知mime页面中的 cmd = getuserinfo
		#查找玩家
        $sql = "SELECT `uid`,`coin` FROM `@@users` WHERE `uno`='{$uno}' LIMIT 1";
        $user = $this->db->query($sql,2);
		
		$this->pushClient($uno,array(
			'cmd' => 'updateusercoin',
			'state' => 200,
			'usercoin' => $user['coin'],
		));

		# 处理VIP升级
		$this->updateUserVip($user['uid']);


        $this->dialogue(array(
            'type' => 'success',
            'text' => "手动给玩家[{$uno}]充值{$amount}成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    // 手动确认充值成功
    public function rechargelog_success(){
        $id = $this->existsKeyInArray('id', $_GET, 'N');
        $rechargeid = $this->existsKeyInArray('rechargeid', $_GET, 'S');
        $amount = $this->existsKeyInArray('amount', $_GET, 'F');
        if(!$id) core::__403();

        $basepath = '/members/rechargelog_success';

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<input type="hidden" name="id" value="'.$id.'" />';
        $html .= '<input type="hidden" name="rechargeid" value="'.$rechargeid.'" />';
        $html .= '<dl><dt>订单编号：</dt><dd>'.$rechargeid.'</dd></dl>';
        $html .= '<dl><dt>到帐金额：</dt><dd><input type="text" name="rechargeamount" value="'.$amount.'" placeholder="具体的到帐金额" /> </dd></dl>';
        $html .= '<dl><dt>备注内容：</dt><dd><input type="text" name="info" placeholder="银行流水号或入帐银行名称" /> </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    // 充值失败
    public function rechargelog_cancel(){
        $id = $this->existsKeyInArray('id', $_GET, 'N');
        $rechargeid = $this->existsKeyInArray('rechargeid', $_GET, 'S');
        $amount = $this->existsKeyInArray('amount', $_GET, 'F');
        if(!$id) core::__403();

        $nowtime = time();
        $rechargelog = $this->mod_rechargelog_item($id);
        if(!empty($rechargelog['state'])) core::error('本订单已处理！');

        $updateid = $this->table_row_save('@@users_recharge',
            array(
                'state'=>2,
                'info'=>'',
                'actionuid' => $rechargelog['uid'],
                'actionip' => $this->ip(true),
                'rechargetime' => $nowtime,
                'rechargeamount'=>0,
            ),
            array('id'=>$id),
            true);
        if(!$updateid) core::error('操作不成功');
        $this->addLog($this->authid,__FUNCTION__,$id,'');

        $this->dialogue(array(
            'type' => 'success',
            'text' => "充值状态已设为【不成功】",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    public function rechargelog_success_save(){
        $id = $this->existsKeyInArray('id', $_POST, 'N');
        $rechargeid = $this->existsKeyInArray('rechargeid', $_POST, 'S');
        $rechargeamount = $this->existsKeyInArray('rechargeamount', $_POST, 'F');
        $info = $this->existsKeyInArray('info', $_POST, 'S');
        if(!$id) core::__403();
        if(empty($info)) core::error('须填写到帐的银行流水号或入帐银行');
        if(empty($rechargeamount)) core::error('请填写具体入帐金额');
        $nowtime = time();
        $rechargelog = $this->mod_rechargelog_item($id);
        if(!empty($rechargelog['state'])) core::error('本订单已处理！');

        $updateid = $this->table_row_save('@@users_recharge',
            array(
                'state'=>1,
                'info'=>$info,
                'actionuid' => $rechargelog['uid'],
                'actionip' => $this->ip(true),
                'rechargetime' => $nowtime,
                'rechargeamount'=>$rechargeamount,
            ),
            array('id'=>$id),
            true);
        if(!$updateid) core::error('充值操作不成功');
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        # 找出对应线路的充值赠送
        $give = $this->mod_rechargelog_item_give($id);
        $giveCoin = 0;
        if($give['coin']>0)
        {
            $giveCoin = $rechargeamount * $give['coin'] / 100;
            $giveCoin = floatval($this->formatCoin($giveCoin));
        }
        # 入帐到玩家帐号
        //开始事务处理
        $this->db->transaction('begin');
        try{
            $coinLog = array(
                'uid' => $rechargelog['uid'],
                'coin' => $rechargeamount,
                'liqtype' => 21,
                'ex1' => $id,
                'ex2' => $rechargeid,
                'ex3' => $info,
            );
            $this->set_coin($coinLog);

            # 当前线路是否有赠送
            if($giveCoin>0){
                $this->set_coin(array(
                    'uid' => $rechargelog['uid'],
                    'coin' => $giveCoin,
                    'liqtype' => 27,
                    'ex1' => $id,
                    'ex2' => $rechargeid,
                    'ex3' => $rechargeamount .'×'.$give['coin'].'%',
                ));
            }

            # 当前VIP等级充值赠送 - 后续将升级 VIP 等级，但本次还是按当前的等级赠送
            if($rechargelog['usertype'] == 1) {
                # 找出用户VIP等级,如果有充值赠送的将赠送给玩家
                $sql = "SELECT `rechargediscd` FROM `@@userlevel` WHERE `lid`=" . $rechargelog['userlevel'] . " LIMIT 1";
                $vipdb = $this->db->query($sql,2);
                if (floatval($vipdb['rechargediscd']) > 0) {
                    $rechargediscdcoin = $rechargeamount * $vipdb['rechargediscd'] / 100;
                    if ($rechargediscdcoin > 0) {
                        $this->set_coin(array(
                            'uid' => $rechargelog['uid'],
                            'gameid' => 0,
                            'coin' => $rechargediscdcoin,
                            'liqtype' => 26,
                            'ex1' => $rechargelog['id'],
                            'ex2' => $rechargeid,
                            'ex3' => $rechargeamount . '×' . $vipdb['rechargediscd'] . '%',
                        ));
                    }
                }
            }
            /*
            # 当前线路是否有赠送
            if($giveCoin>0)
            {
                $this->set_coin(array(
                    'uid' => $rechargelog['uid'],
                    'gameid' => 0,
                    'coin' => $giveCoin,
                    'liqtype' => 26,
                    'ex1' => $rechargelog['id'],
                    'ex2' => $rechargeid,
                    'ex3' => $rechargeamount . '×' . $give['coin'] . '%',
                ));
            }
            */
            # 充值成功后把上级的代理推荐赠送的金额激活
            # $sql = "UPDATE `@@givecoinlog` SET `state`=1 WHERE `uid`=".$rechargelog['parentid']." AND `liqtype`=25 AND `ex1`=".$rechargelog['uid']." AND `state`=0 LIMIT 1";
            # $this->db->query($sql,1);

            $sql = "SELECT `uid`,`uno`,`nickname`,`recharge`,`agentlevel` FROM @@users WHERE `uid`=".$rechargelog['uid'];
            //echo $sql;
            $rc = $this->db->query($sql,2);

            # 查看当前用户的代理等级及充值折扣
            //$agentupdategiveway = intval($this->config['agentupdategiveway']);
            if( $rechargelog['usertype'] == 2) {
                # 找出代理线
                $agent = $this->getAgentLevelForLid($rc['agentlevel']);
                $rechargediscd = $agent['rechargediscd'];
                $rechargediscdcoin = $rechargediscd * $rechargeamount / 100;
                $rechargediscdcoin = $this->formatCoin($rechargediscdcoin);
                if (floatval($rechargediscdcoin) > 0) {
                    $this->set_coin(array(
                        'uid' => $rechargelog['uid'],
                        'gameid' => 0,
                        'coin' => $rechargediscdcoin,
                        'liqtype' => 26,
                        'ex1' => $rechargelog['id'],
                        'ex2' => $rechargeid,
                        'ex3' => $rechargeamount . '×' . $rechargediscd . '%',
                    ));
                }
            }

            //$rechargeCount = $rc['_TOTAL'];
            # 充值总额要加上本次的充值金额，用户的充值总额是要在setCoin执行后才会更新
            $rechargeSum = floatval($rc['recharge']) + floatval($rechargeamount);

            $sumrechargecoin = $this->config['sumrechargecoin'];
            # $sumrechargegive = $utility->getSystemParas('sumrechargegive');

            # 当用户充值的金额达到指定的赠送额度后，给当前用户和推荐人加入赠送的金额
            if($rechargeSum >= floatval($sumrechargecoin)) {
                $sql = "SELECT `uid`,`uno`,`nickname`,`coin`,`score`,`parentid`,`parents`,`tel`,`agentlevel`,`userlevel` FROM `@@users` WHERE `uid`='" . $rechargelog['parentid'] . "' AND `usertype`>0 LIMIT 1";
                $parent = $this->db->query($sql, 2);
                if($parent) {
                    # 查找是否已经赠送,如果有赠送即不再赠送，没有就赠送过去
                    $sql = "SELECT COUNT(1) AS _TOTAL FROM `@@recharge_give` WHERE `uid`={$parent['uid']} AND `fromuid`={$rechargelog['uid']} LIMIT 1";
                    $isgive = $this->db->query($sql, 2);
                    if($isgive['_TOTAL'] == 0) {
                        $sql = 'SELECT `pushusergive` FROM `@@agentlevel` WHERE `lid`=' . $parent['agentlevel'] . ' LIMIT 1';
                        $agent = $this->db->query($sql, 2);
                        if ($agent['pushusergive'] > 0) {
                            $this->set_coin(array(
                                    'uid' => $parent['uid'],
                                    'coin' => $agent['pushusergive'],
                                    'liqtype' => 25,
                                    'ex1' => $rechargelog['uid'],
                                    'ex2' => '',
                                    'ex3' => $rc['nickname'].'('.$rc['uno'].')存款满' . $sumrechargecoin . '赠送',
                                )
                            );
                            # 有赠送的把它记录到赠送库里
                            $recharge_give = array(
                                "uid" => $parent['uid'],
                                "fromuid" => $rechargelog['uid'],
                                "coin" => $agent['pushusergive'],
                                "actiontimes" => time(),
                                "liqtype" => 1,
                            );
                            $this->table_row_save('@@recharge_give', $recharge_give, array(),false);
                        }
                    }
                }
            }

            if(empty($rc['recharge'])) {
                # 首次成功充值成功的金额大于firstrechargecoin时赠送firstrechargegive
                $firstrechargecoin = $this->config['firstrechargecoin'];
                $firstrechargegive = $this->config['firstrechargegive'];

                if (floatval($firstrechargegive) > 0 AND $rechargeamount >= floatval($firstrechargecoin)) {
                    //$firstrechargegivecoin = $buyer_pay_amount * $firstrechargegive / 100;
                    $firstrechargegivecoin = $firstrechargegive;
                    $this->set_coin(array(
                        "uid" => $rechargelog['uid'],
                        'gameid' => 0,
                        'coin' => $firstrechargegivecoin,
                        'liqtype' => 32,
                        'ex1' => $rechargelog['uid'],
                        'ex2' => $rechargeid,
                        'ex3' => $rechargeamount . '×' . $firstrechargegive . '%',

                    ));
                }
            }

            # 升级玩家的 VIP 等级
            $this->updateUserVip($rechargelog['uid']);

            $this->db->transaction('commit');
        }catch(Exception $e){
            $this->db->transaction('rollBack');
            core::error($e->getMessage());
        }

        # 处理VIP升级
        $this->updateUserVip($rechargelog['uid']);

        $this->dialogue(array(
            'type' => 'success',
            'text' => "手动确认玩家充值成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }

    //获取参数
    private function rechargelog_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['paywayid'] = $this->existsKeyInArray('paywayid',$para,'N');
        $args['state'] = $this->existsKeyInArray('state',$para,'S');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        return $args;
    }
    //拼装页面参数
    private function rechargelog_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['paywayid'])) $page_args['paywayid'] = $args['paywayid'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if(!empty($args['state'])) $page_args['state'] = $args['state'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function rechargelog()
    {
        $basepath = '/members/rechargelog';

        $get = true;
        $args = $this->rechargelog_get_args($get);
        $page_args = $this->rechargelog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_rechargelog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/rechargelog",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'total' => $datas['total'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'banks' => $this->mod_banklist_for_selectoption(),
            'payways' => $this->mod_payway_list(),
            'thishref' => '/members/rechargelog',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe',
        ));
    }
    # endregion

    # region 提现处理
    // 提现成功
    public function cashlog_success(){
        $id = $this->existsKeyInArray('id', $_GET, 'N');
        if(!$id) core::__403();
        $updateid = $this->update_state('@@users_cash',$id);
        if(!$updateid) core::error('提现失败');
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "提现成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    // 提现失败要分两步，第一步填写失败的原因，第二步确认更新提现状态
    public function cashlog_faild()
    {
        $id = $this->existsKeyInArray('id', $_GET, 'N');
        $cashid = $this->existsKeyInArray('cashid', $_GET, 'S');
        if(!$id) core::__403();

        $basepath = '/members/cashlog_faild';

        $errorInfos = $this->mod_users_cash_faild_info();

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<input type="hidden" name="id" value="'.$id.'" />';
        $html .= '<dl><dt>订单编号：</dt><dd>'.$cashid.'</dd></dl>';
        $html .= '<dl><dt>预设错误：</dt><dd><select name="errorinfoselect">';
        $html .= '<option value="">选择预设的错误信息</option>';
        foreach ($errorInfos as $k=>$v){
            $html .= '<option value="'.$v['title'].'">'.$v['title'].'</option>';
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>失败原因：</dt><dd><input type="text" name="info" placeholder="请填写提现失败的具体原因" /> </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '保存',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));

    }
    public function cashlog_faild_save(){
        $id = $this->existsKeyInArray('id', $_POST, 'N');
        $info = $this->existsKeyInArray('info', $_POST, 'S');
        if(!$id) core::__403();
        if(empty($info)) core::error('须填写具体的失败原因');
        $updateid = $this->table_row_save('@@users_cash',
            array('state'=>2,'info'=>$info),
            array('id'=>$id),
            true);
        if(!$updateid) core::error('设置提现失败错误');
        $sql = "SELECT * FROM `@@users_cash` WHERE `id`=".$id;
        $cashItem = $this->db->query($sql,2);

        //开始事务处理
        $this->db->transaction('begin');
        try{
            $coinLog = array(
                'uid' => $cashItem['uid'],
                'coin' => $cashItem['amount'],
                'liqtype' => 20,
                'ex1' => $cashItem['id'],
                'ex2' => $cashItem['cashid'],
                'ex3' => '提现失败：'.$info,
            );
            $this->set_coin($coinLog);

            $this->db->transaction('commit');
        }catch(Exception $e){
            $this->db->transaction('rollBack');
            core::error($e->getMessage());
        }

        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "当前订单已设置成失败",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    //获取参数
    private function cashlog_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['bankid'] = $this->existsKeyInArray('bankid',$para,'N');
        $args['state'] = $this->existsKeyInArray('state',$para,'S');
        $args['field'] = $this->existsKeyInArray('field',$para,'S');
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        return $args;
    }
    //拼装页面参数
    private function cashlog_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['bankid'])) $page_args['bankid'] = $args['bankid'];
        if(!empty($args['field'])) $page_args['field'] = $args['field'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if(!empty($args['state'])) $page_args['state'] = $args['state'];
        $page_args['page'] = '{page}';
        return $page_args;
    }

    public function cashlog()
    {
        $basepath = '/members/cashlog';

        $get = true;
        $args = $this->cashlog_get_args($get);
        $page_args = $this->cashlog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_cashlog_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/cashlog",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'total' => $datas['total'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'banks' => $this->mod_banklist_for_selectoption(),
            'thishref' => '/members/cashlog',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe',
        ));
    }
    # endregion

    # region 自动抢发包用户管理
    private function autosend_list_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$fromTime);
        $args['gameid'] = $this->existsKeyInArray('gameid',$para,'S');
        return $args;
    }
    //拼装页面参数
    private function autosend_list_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if($args['gameid']!='') $page_args['gameid'] = $args['gameid'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function autosend_list(){
        /*
        $sql = "SELECT uid FROM `@@autosend`";
        $users = $this->db->query($sql,3);
        foreach ($users AS $v){
            $this->db->query('UPDATE `@@users` SET usertype=3 WHERE uid='.$v['uid'],1);
        }
        */
        $basepath = '/members/autosend_list';

        $get = true;
        $args = $this->autosend_list_get_args($get);
        $page_args = $this->autosend_list_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_autosend_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/autosend_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'games' => $this->mod_games_items(),
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => $basepath,
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }

    private function autosend_list_add_edit_args($get = true){
        $para = $get ? $_GET : $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['uid'] = $this->existsKeyInArray('uid',$para,'N');
        $args['gameid'] = $this->existsKeyInArray('gameid',$para,'N');
        return $args;
    }

    public function autosend_list_add(){

        $uid = $this->existsKeyInArray('uid',$_GET,'S','');

        $basepath = '/members/autosend_list';

        $games = $this->mod_games_items();

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家UID：</dt><dd><input type="text" name="uid" class="mint" value="'.$uid.'" </dd></dl>';
        $html .= '<dl><dt>对应游戏：</dt><dd><select name="gameid">';
        foreach ($games AS $key=>$val) {
            $html .= '<option value="' .$key.'">'.$val.'</option>';
        }
        $html .= '</select></dd></dl>';
        $html .= '<dl><dt>备注：</dt><dd>系统会自动把UID用户['.$uid.']定为内部会员</dd>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }

    public function autosend_list_add_save()
    {
        $args['uid'] = $this->existsKeyInArray('uid',$_POST,'N');
        //$args['gameid'] = $this->existsKeyInArray('gameid',$_POST,'N', 1);
        $data = $this->getRow('@@users','uno,nickname',array('uid'=>$args['uid']));
        if(!$data)  core::error('用户不存在，请重试');

        $args = $this->autosend_list_add_edit_args(false);


        $_result = $this->table_row_save('@@autosend',$args,null,false);
        if(!$_result) core::error("添加[".$args['uid']."]失败".$_result);

        $sql = 'UPDATE `@@users` SET `usertype`=3 WHERE `uid`='.$args['uid'];
        $this->db->query($sql,1);

        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['uid']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }

    public function autosend_list_delete()
    {
        $uid = $this->existsKeyInArray('uid',$_GET,'N');
        if(!$uid) core::__403();
        //删除条件检测
        $deleteid = $this->db->delete('@@autosend',array('uid'=>$uid));
        if(!$deleteid) core::error('删除操作失败');
        $this->addLog($this->authid,__FUNCTION__,$deleteid);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }

    public function autosend_list_sendforgameid()
    {
        $gameid = $this->existsKeyInArray('gameid',$_GET,'N');
        $result = $this->mod_autosend_togame($gameid);
        if($result['state']==200) {
            $beforResult = array(
                'state' => 200,
                'cmd' => 'newred',
                'gameid' => $result['gameid'],
                'datas' => $result['datas'],
            );
            Gateway::sendToGroup($result['groupname'], json_encode($beforResult));
            core::success($result['groupname'] . '--' . $result['datas']['issue'].'发包成功');
        }else{
            core::error('发包失败');
        }
    }

    # endregion

    # region 自动发包过程
    public function autogameover_add()
    {
        # 统计房间的红包数
        $sql = "SELECT g.id,IFNULL(count1,0) AS count FROM `@@games` g LEFT JOIN (SELECT l.gameid,COUNT(1) AS count1 FROM `@@bets` l WHERE (l.`overtime` - (UNIX_TIMESTAMP() - l.`begintimes`)) > 0 AND l.`state`=0 GROUP BY l.`gameid`) t1 ON t1.gameid=g.id";
        $gameCount = $this->db->query($sql,3);
        foreach ($gameCount as $key=>$v)
        {
            if($v['count']==0) {
                $result = $this->mod_autosend_togame($v['id']);
                if ($result['state'] == 200) {
                    $beforResult = array(
                        'state' => 200,
                        'cmd' => 'newred',
                        'gameid' => $result['gameid'],
                        'datas' => $result['datas'],
                    );
                    Gateway::sendToGroup($result['groupname'], json_encode($beforResult));
                }
                sleep(5);
            }
        }


    }
    # endregion

    # region 单个超时红包处理
    public function gameover()
    {
        $issue = $this->existsKeyInArray('issue',$_GET,'S');

        $sql = "SELECT `id`,`issue`,`gameid`,`need` FROM `@@bets` WHERE `issue`='".$issue."' LIMIT 1";
        $data = $this->db->query($sql,2);

        $issue = $data['issue'];
        $gameid = $data['gameid'];
        $need = $data['need'];

        if(empty($issue)) {
            $this->dialogue(array(
                'type' => 'error',
                'text' => "期号参数不正确",
                'auto' => true,
                'yes' => array(
                    'text' => '关闭',
                ),
            ));
            return false;
        }

        $url = str_replace('https://','http://',$this->config['apiurl']).'/game/gametimeout?';
        $url .= 'red_issue='.$issue;
        //初始化
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        //执行并获取HTML文档内容
        $output = curl_exec($ch);
        //释放curl句柄
        curl_close($ch);
        //打印获得的数据

        //var_dump($output);

        if(strtolower($output)!='null') {

            $data = json_decode($output, true);


            if(count($data)>0 && $data['state']!=404) {
                Gateway::sendToGroup('game_'.$gameid, array(
                    'cmd'=>'updatered',
                    'state' => 200,
                    'msgid' => 10024,
                    'issue' => $issue,
                    'cur' => $need,
                ));
                $this->dialogue(array(
                    'type' => 'success',
                    'text' => "第{$issue}期红包参与人数不足超时取消成功！",
                    'auto' => true,
                    'yes' => array(
                        'text' => '关闭',
                    ),
                ));
            }else{
    
                $this->dialogue(array(
                    'type' => 'error',
                    'text' => "操作失败1",
                    'auto' => true,
                    'yes'  => array(
                        'text' => '关闭',
                    ),
                ));
            }
        }else{
            $this->dialogue(array(
                'type' => 'error',
                'text' => "操作失败2",
                'auto' => true,
                'yes'  => array(
                    'text' => '关闭',
                ),
            ));
        }
        //释放curl句柄
        //curl_close($ch);
        //打印获得的数据
    }

    # endregion

    # region 自动处理超时
    public function autogameover()
    {
        $sql = "SELECT `id`,`issue`,`gameid`,`need` FROM `@@bets` WHERE (`overtime` - (UNIX_TIMESTAMP() - `begintimes`)) < -5 AND `state`=0 AND `need`>`cur` ORDER BY `id` ASC LIMIT 1";
        $data = $this->db->query($sql,2);

        $issue = $data['issue'];
        $gameid = $data['gameid'];
        $need = $data['need'];

        if(empty($issue))
        {
            core::error("期号参数不正确");
        }
        $url = str_replace('https://','http://',$this->config['apiurl']).'/game/gametimeout?';
        $url .= 'red_issue='.$issue;
        //初始化
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        //执行并获取HTML文档内容
        $output = curl_exec($ch);
        //释放curl句柄
        curl_close($ch);
        //打印获得的数据

        if(strtolower($output)!='null') {
            $data = json_decode($output, true);
            if(count($data)>0) {
                Gateway::sendToGroup('game_'.$gameid, array(
                    'cmd'=>'updatered',
                    'state' => 200,
                    'issue' => $issue,
                    'cur' => $need,
                ));
                core::success("第{$data['timeoutdata']['issue']}期红包参与人数不足超时取消成功！");
            }else{
                core::error($issue."超时退回-操作失败");
            }
        }else{
            core::error($issue."超时退回-操作失败");
        }

    }
    # endregion

    # region 自动给发包的用户充值
    public function autosend_list_recharge()
    {
        $sql = 'SELECT a.uid,u.uno,u.coin,u.usertype FROM `@@autosend` a,`@@users` u WHERE u.uid=a.uid';
        $users = $this->db->query($sql, 3);

        $paras['nowtime'] = time();

        foreach($users as $key=>$user) {
            $amount = 1000000.00;
            $info = '系统自动充值';

            # 入帐到玩家帐号
            //开始事务处理
            $this->db->transaction('begin');
            try {
                # 记录充值日志
                # 生成订单号
                $rechargeid = $this->neworderno();

                # 保存到充值日志中
                $recharge_log = array(
                    'uid' => $user['uid'],
                    'rechargeid' => $rechargeid,
                    'amount' => $amount,
                    'rechargeamount' => $amount,
                    'coin' => $user['coin'],
                    'bankid' => 24,
                    'paywayid' => 1,
                    'lineid' => 1,
                    'state' => 1,
                    'actiontime' => $paras['nowtime'],
                    'info' => $info,
                    'usertype' => 3,
                );
                $id = $this->table_row_save('@@users_recharge', $recharge_log, false);
                $coinLog = array(
                    'uid' => $user['uid'],
                    'coin' => $amount,
                    'liqtype' => 21,
                    'ex1' => $id,
                    'ex2' => $rechargeid,
                );
                $this->set_coin($coinLog);
                $this->db->transaction('commit');
            } catch (Exception $e) {
                $this->db->transaction('rollBack');
                core::error($e->getMessage());
            }
        }
    }

    # endregion

    # region 概率用户管理
    //获取分布及查找参数
    private function probability_list_get_args($get = true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S');
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S');
        $args['sortfield'] = $this->existsKeyInArray('sortfield',$para,'S', 'profit');
        $args['sorttype'] = $this->existsKeyInArray('sorttype',$para,'S', 'DESC');
        $args['usertype'] = $this->existsKeyInArray('usertype',$para,'S','');
        $args['t'] = $this->existsKeyInArray('t',$para,'N');
        return $args;
    }
    //拼装页面参数
    private function probability_list_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if(!empty($args['sortfield'])) $page_args['sortfield'] = $args['sortfield'];
        if(!empty($args['sorttype'])) $page_args['sorttype'] = $args['sorttype'];
        if($args['usertype']!='') $page_args['usertype'] = $args['usertype'];
        $page_args['t'] = $args['t'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    //数据列表
    public function probability_list(){
        $basepath = '/members/probability_list';

        $get = true;
        $args = $this->probability_list_get_args($get);
        $page_args = $this->probability_list_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_probability_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);


        $this->display("members/probability_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/probability_list',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }

    private function probability_list_add_edit_args($get = true){
        $para = $get ? $_GET : $_POST;
        unset($para["client_type"]);
        $args = array();
        $args['uid'] = $this->existsKeyInArray('uid',$para,'N');
        $args['winpoints'] = $this->existsKeyInArray('winpoints',$para,'F');
        $args['effectivetime'] = $this->existsKeyInArray('effectivetime',$para,'N');
        $args['jointime'] = $this->existsKeyInArray('jointime',$para,'S');
        $args['jointime'] = strtotime($args['jointime']);
        return $args;
    }

    public function probability_list_add(){

        $uid = $this->existsKeyInArray('uid',$_GET,'S','');

        $basepath = '/members/probability_list';

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="add_save" action="'.$basepath.'_add_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家UID：</dt><dd><input type="text" name="uid" class="mint" value="'.$uid.'" /> </dd></dl>';
        $html .= '<dl><dt>盈亏概率：</dt><dd><input type="text" name="winpoints" class="mint" value="10" /> % </dd></dl>';
        $html .= '<dl><dt>加入时间：</dt><dd><input type="text" name="jointime" class="int" value="'.date('Y-m-d H:i:s',time()).'" /> </dd></dl>';
        $html .= '<dl><dt>有效时长：</dt><dd><input type="text" name="effectivetime" class="mint" value="86400" /> 秒 </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=add_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }

    public function probability_list_add_save()
    {
        $args = $this->probability_list_add_edit_args(false);
        $_result = 1;
        try {
            $_result = $this->table_row_save('@@users_probability', $args, null, false);
        }catch (PDOException $e){
            core::error("添加[".$args['uid']."]失败".$e->getMessage());
        }
        // if(!$_result) core::error("添加[".$args['uid']."]失败".$_result);

        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "添加[".$args['uid']."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }

    public function probability_list_edit(){

        $uid = $this->existsKeyInArray('uid',$_GET,'S','');

        $sql = "SELECT * FROM `@@users_probability` WHERE `uid`=".$uid.' LIMIT 1';
        $data = $this->db->query($sql, 2);

        $basepath = '/members/probability_list';

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="edit_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<dl><dt>玩家UID：</dt><dd><input type="text" name="uid" class="mint" value="'.$data['uid'].'" /> </dd></dl>';
        $html .= '<dl><dt>盈亏概率：</dt><dd><input type="text" name="winpoints" class="mint" value="'.$data['winpoints'].'" /> % </dd></dl>';
        $html .= '<dl><dt>加入时间：</dt><dd><input type="text" name="jointime" class="int" value="'.date('Y-m-d H:i:s',$data['jointime']).'" /> </dd></dl>';
        $html .= '<dl><dt>有效时长：</dt><dd><input type="text" name="effectivetime" class="mint" value="'.$data['effectivetime'].'" /> 秒 </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=edit_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }

    public function probability_list_edit_save()
    {
        $args = $this->probability_list_add_edit_args(false);
        $uid = intval($args['uid']);
        unset($args['uid']);

        $_result = $this->db->update('@@users_probability',$args,array('uid'=>$uid));
        if(!$_result) core::error("编辑[".$uid."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "编辑[".$uid."]成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }

    public function probability_list_delete()
    {
        $uid = $this->existsKeyInArray('uid',$_GET,'N');
        if(!$uid) core::__403();
        //删除条件检测
        $deleteid = $this->db->delete('@@users_probability',array('uid'=>$uid));
        if(!$deleteid) core::error('删除操作失败');
        $this->addLog($this->authid,__FUNCTION__,$uid,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "删除操作成功",
            'auto' => true,
            'yes'  => array(
                'text' => '我知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    # endregion

    # region 会员登录日志
    private function loginlog_get_args($get){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,true,$this->pagesize);
        return $args;
    }
    private function loginlog_page_args($args){
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    public function loginlog(){
        $get = true;
        $args = $this->loginlog_get_args($get);
        $page_args = $this->loginlog_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_loginlog($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("members/loginlog",array(
            'basepath' => '/members/loginlog',
            'datas' => $datas['datas'],
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    # endregion

    # region 代理链接管理
    private function agentlinks_list_get_args($get=true){
        $para = $get ? $_GET : $_POST;
        $args = array();
        $fromTime = date('Y-01-01',time());
        $endTime = date('Y-m-d',time());
        $args['sKey'] = $this->existsKeyInArray('sKey',$para,'S');
        $args['usertype'] = $this->existsKeyInArray('usertype',$para,'S');
        $args['sortfield'] = $this->existsKeyInArray('sortfield',$para,'S');
        $args['sorttype'] = $this->existsKeyInArray('sorttype',$para,'S');
        $args['ps'] = $this->existsKeyInArray('ps',$para,'N',$this->pagesize);
        $args['fromTime'] = $this->existsKeyInArray('fromTime',$para,'S',$fromTime);
        $args['toTime'] = $this->existsKeyInArray('toTime',$para,'S',$endTime);
        return $args;
    }
    //拼装页面参数
    private function agentlinks_list_page_args($args)
    {
        $page_args = array();
        if(!empty($args['sKey'])) $page_args['sKey'] = $args['sKey'];
        if(!empty($args['usertype'])) $page_args['usertype'] = $args['usertype'];
        if(!empty($args['ps'])) $page_args['ps'] = $args['ps'];
        if(!empty($args['fromTime'])) $page_args['fromTime'] = $args['fromTime'];
        if(!empty($args['toTime'])) $page_args['toTime'] = $args['toTime'];
        if($args['sortfield'] != '') $page_args['sortfield'] = $args['sortfield'];
        if($args['sorttype'] != '') $page_args['sorttype'] = $args['sorttype'];
        $page_args['page'] = '{page}';
        return $page_args;
    }
    public function agentlinks_list(){
        $basepath = '/members/agentlinks_list';

        $get = true;
        $args = $this->agentlinks_list_get_args($get);
        $page_args = $this->agentlinks_list_page_args($args);
        $args['page_current'] = $this->get_page();

        $datas = $this->mod_agentlinks_list($args);
        $args['page_max'] = $this->get_maxpage($args['ps'],$datas['record']);

        $this->display("members/agentlinks_list",array(
            'basepath' => $basepath,
            'datas' => $datas['datas'],
            'agentLevel' => $this->mod_members_agentLevel_forSelect(),
            'record' => $datas['record'],
            'page_max' => $args['page_max'],
            'thishref' => '/members/agentlinks_list',
            'page_current' => $args['page_current'],
            'page_url' => http_build_query($page_args),
            'extra' => '',
            'searchdata' => $args,
            'container' => '#iframe'
        ));
    }
    public function agentlinks_list_state(){
        $id = $this->existsKeyInArray('id',$_REQUEST,'N');
        if(!$id) core::error('参数错误');
        $updateid = $this->update_state('@@agentlinks',$id);
        $this->addLog($this->authid,__FUNCTION__,$id,'');
        $this->dialogue(array(
            'type' => 'success',
            'text' => "推广链接状态更新成功",
            'auto' => true,
            'yes'  => array(
                'text' => '知道了',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
        ));
    }
    public function agentlinks_list_edit(){

        $id = $this->existsKeyInArray('id',$_GET,'N');

        $sql = "SELECT rebate FROM `@@agentlinks` WHERE `id`=".$id.' LIMIT 1';
        $data = $this->db->query($sql, 2);

        $basepath = '/members/agentlinks_list';

        $html = '<div id="mainbody">';
        $html .= '<div class="main">';
        $html .= '<div class="info">';
        $html .= '<form name="edit_save" action="'.$basepath.'_edit_save"  method="POST" target="ajax" func="form_submit">';
        $html .= '<input type="hidden" name="id" value="'.$id.'" />';
        $html .= '<dl><dt>链接返点：</dt><dd><input type="text" name="rebate" class="mint" value="'.$data['rebate'].'" /> % </dd></dl>';
        $html .= '</form>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $this->dialogue(array(
            'class' => '',
            'body' => $html,
            'yes'  => array(
                'text' => '确定',
                'func' => '$("form[name=edit_save]").submit();',
            ),
            'no'  => array(
                'text' => '关闭',
            ),
        ));
    }
    public function agentlinks_list_edit_save(){
        $args = array(
            'rebate' => $this->existsKeyInArray('rebate',$_POST,'F'),
        );
        $id = $this->existsKeyInArray('id',$_POST,'N');

        # 找出代理自己的返点，如果有直属用户了就不能减小，只能加大

        $_result = $this->db->update('@@agentlinks',$args,array('id'=>$id));
        if(!$_result) core::error("编辑[".$id."]失败");
        $this->addLog($this->authid,__FUNCTION__,$_result);
        $this->dialogue(array(
            'type' => 'success',
            'text' => "编辑推广链接 - 成功",
            'auto' => true,
            'yes'  => array(
                'text' => '刷新',
                'func' => '$("#btn_refresh").trigger("click");',
            ),
            'no'  => array(
                'text' => '返回',
            ),
        ));
    }
    # endregion

}